﻿using Comm.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Comm.Web.View
{
    public partial class OrderComfirm :Basepage
    {
        BLL.CartService bllItem =new BLL.CartService ();
        BLL.CheckAddressService blladdress = new BLL.CheckAddressService();
        protected string strHtml = string.Empty;
        protected string straddHtml = string.Empty;
        protected decimal totleMoney = 0;
        public override void SonLoad()
        {
            if (!IsPostBack)
            {
                BindShop();
            }
            GetAddressList();
        }

        public void BindShop() 
        {
            StringBuilder sb = new StringBuilder();
            Cart car = bllItem.GetUserCar(UserNow.uId, 0);
            foreach (CarItems model in car.ItemList) 
            {
                sb.Append("<tr class=\"align_Center\">");
                sb.Append("<td style=\"PADDING-BOTTOM: 5px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 5px\">" + model.bookId + "</td>");
                sb.Append(" <td class=align_Left><a onmouseover=\"\" onmouseout=\"\" onclick=\"\" id=\""+model.bookId+"\" EditId=\"EditId\" style=\"cursor:pointer;\">" + model.BookMODEL.Title + "</a></td>");
                sb.Append("<td><span class=\"price\">￥" + model.BookMODEL.UnitPrice + "</span></td>");
                sb.Append("<td>" + model.count + "</td>   </tr>");
                totleMoney = totleMoney + (model.count * model.BookMODEL.UnitPrice);
            }
            strHtml = sb.ToString();
        }

        public void GetAddressList() 
        {
            StringBuilder sbd = new StringBuilder();
            IList<CheckAddress> list= blladdress.GetAddressList(UserNow.uId);
            if (list != null) 
            {
                sbd.Append("<table id=\"tbList\" style=\"width:90%;\">");
                sbd.Append("<tr id=\"trNav\"><th colspan=\"6\">用户【"+UserNow.uLoginName+"】的收货地址</th></tr>");
                sbd.Append("<tr><th>操作</th><th>收货人</th><th>地址</th><th>电话</th><th>邮编</th><th>是否为默认地址</th></tr>");
               foreach(CheckAddress model in list)
               {
                   sbd.Append("<tr><td><input type=\"checkbox\" name=\"chk_"+model.Id+"\" value=\"checkbox\" style=\"width:10%;\"/></td>");
                   sbd.Append("<td style=\"width:10%\">"+model.UserName+"</td>");
                   sbd.Append("<td style=\"width:35%\">"+model.Address+"</td>");
                   sbd.Append("<td style=\"width:25%\">" + model.TelPhone + "</td>");
                   sbd.Append("<td style=\"width:10%\">" + model.postCode + "</td>");
                   string IsEdit = string.Empty;
                   if (model.statu == false)
                   {
                       IsEdit = "否";
                   }
                   else 
                   {
                       IsEdit = "是";
                   }
                   sbd.Append("<td style=\"width:10%\">" + IsEdit + "<a  href=\"javascript:void(0)\" title=\"设置\" onclick=\"getMoRenAddress(" + model.Id + ",this)\" id=\"" + model.Id + "\" style=\"cursor:pointer; margin-left:5px;\">设置</a></td></tr>");
               }
               sbd.Append("</table>");
            }
            straddHtml = sbd.ToString();

        }
    }
}